package com.jhws.business.alert.api;

import com.jhws.business.comm.bo.TblCommDimBo;
import com.jhws.business.comm.service.ITblCommDimService;
import com.jhws.common.base.bo.JsonRespData;
import com.jhws.util.AccountsUtils;
import com.jhws.util.LogHelper;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/v2/alert")
public class alertApiV2 extends alertAPI {
    @Resource
    private ITblCommDimService commDimService;

    /**
     * 室内机报警接口
     *
     * @return
     */
    @RequestMapping({"anon/eventAlert", "eventAlert"})
    @ResponseBody
    public JsonRespData eventAlert(HttpServletRequest request, @RequestBody Map map) throws Exception {
        String commPassword = WebUtils.toHttp(request).getHeader("commPassword");
        if (commPassword == null) {
            return new JsonRespData("", -1, "小区密码错误！");
        }
        String commCode = AccountsUtils.getCommCode("001001010106");
        TblCommDimBo bo = commDimService.findTblCommDimByCommCode(commCode);
        if (!commPassword.equals(bo.getCommPassword())) {
            return new JsonRespData("", -1, "小区密码错误！");
        }
        LogHelper.e("-------------->     " + map.toString());
        return new JsonRespData("", 1, "success");
    }
}
